//
//  MapToolkit.m
//  storeapp
//
//  Created by huangyi on 13-6-14.
//  Copyright (c) 2013年 ios. All rights reserved.
//

#import "Toolkit.h"
#import "NSString+encode.h"
#import "NSString+utils.h"
#import "NSData+utils.h"

@implementation Toolkit

+(CLLocationCoordinate2D)geocoder:(NSString*)address{
    NSNumber *lat=nil;
    NSNumber *lng=nil;
    @try {
        NSString *geocoder=[NSString concatStrings:@"http://api.map.qq.com/geoc/?addr=",address.urlencode, nil];
        NSURL *url=[NSURL URLWithString:geocoder];
        NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
        request.HTTPMethod=@"GET";
        NSHTTPURLResponse *response=nil;
        NSError *error=nil;
        NSData *result=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
        NSDictionary *geo=result.jsonObject;
        geo=geo[@"detail"];
        if (geo!=nil) {
            lat=geo[@"pointy"];
            lng=geo[@"pointx"];
        }
    }
    @catch (NSException *exception) {
        NSLog(@"%@",exception.reason);
    }
    @finally {
    }
    return CLLocationCoordinate2DMake(lat.doubleValue, lng.doubleValue);
}

@end
